package com.example.summary.sort;

import com.alibaba.fastjson.JSON;

/**
 * Created by wzn on 2019/1/5.
 */
public class MaoPao {

    public static void main(String[] args) {
        int[] arr = {9, 7, 3, 10, 11, 23, 4, 1};

        System.out.println(JSON.toJSONString(arr));
        sort2(arr);
        System.out.println(JSON.toJSONString(arr));
    }

    private static void sort(int[] arr) {
        for (int i = 0; i < arr.length - 1; i++) {//外层循环控制排序趟数
            for (int j = 0; j < arr.length - 1 - i; j++) {//内层循环控制每一趟排序多少次
                if (arr[j] > arr[j + 1]) {
                    int temp = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = temp;
                }
            }
        }
    }

    private static void sort2(int[] arr) {
        for (int i = 0; i < arr.length - 1; i++) {
            for (int j = 0; j < arr.length - i - 1; j++) {
                if (arr[j] > arr[j+1]){
                    int temp = arr[j];
                    arr[j] = arr[j+1];
                    arr[j+1] = temp;
                }
            }
        }
    }

}
